/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MCQgui.java
 *
 * Created on May 14, 2011, 11:00:41 PM
 */


/**
 *
 * @author thato
 */
package Lab_v3;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Hashtable;
public class MCQpresentation extends javax.swing.JFrame {

    private JDesktopPane headingPanel = new javax.swing.JDesktopPane();
    private JLabel questionLabel = new javax.swing.JLabel();
    private JLabel questionNumberLabel = new javax.swing.JLabel();
    private JLabel questionOfLabel = new javax.swing.JLabel();
    private  JLabel totalQuestionLabel = new javax.swing.JLabel();
    private JScrollPane questionPanel = new javax.swing.JScrollPane();
    private JTextArea questionTextArea = new javax.swing.JTextArea();
    private JPanel answerPanel = new javax.swing.JPanel();
    private JLabel answerALabel = new javax.swing.JLabel();
    public JRadioButton answerAButton = new javax.swing.JRadioButton();
    private JLabel answerBLabel = new javax.swing.JLabel();
    public JRadioButton answerBButton = new javax.swing.JRadioButton();
    private JLabel answerCLabel = new javax.swing.JLabel();
    public JRadioButton answerCButton = new javax.swing.JRadioButton();
    private JLabel answerDLabel = new javax.swing.JLabel();
    public JRadioButton answerDButton = new javax.swing.JRadioButton();
    private JPanel buttomButtonPanel = new javax.swing.JPanel();
    private JButton previousButton = new javax.swing.JButton();
    public JButton nextButton = new javax.swing.JButton();
    private JButton finishedButton = new javax.swing.JButton();
    public int questionNumber = 1;
    public JButton beginTestButton = new javax.swing.JButton();
	private dbtables_question_metadata dbobject_question_metadata;
private Hashtable object_hastable;
    public MCQpresentation() {
        initPage1Components();
dbobject_question_metadata =  new dbtables_question_metadata("sqlite","mcqTest.db");
    }


    private void initPage1Components() {

        

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        beginTestButton.setText("Begin Test");
	beginTestButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 0, 650)
                .addComponent(beginTestButton)
                .addContainerGap(170, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
            .addGroup(layout.createSequentialGroup()
                .addGap(78, 78, 700)
                .addComponent(beginTestButton)
                .addContainerGap(192, Short.MAX_VALUE))
        );

        pack();
    }    



    public void initPage2Components() {

        
      	//Group the radio buttons.
        ButtonGroup group = new ButtonGroup();
        group.add(answerAButton);
	group.add(answerBButton);
	group.add(answerCButton);
	group.add(answerDButton);

	answerAButton.setActionCommand("A");
	answerBButton.setActionCommand("B");
	answerCButton.setActionCommand("C");
	answerDButton.setActionCommand("D");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        headingPanel.setBackground(new java.awt.Color(3, 125, 148));

        questionLabel.setText("Question");
        questionLabel.setBounds(130, 0, 70, 18);
        headingPanel.add(questionLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        questionNumberLabel.setText(Integer.toString(questionNumber));
        questionNumberLabel.setBounds(200, 0, 20, 18);
        headingPanel.add(questionNumberLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        questionOfLabel.setText("of");
        questionOfLabel.setBounds(215, 0, 20, 20);
        headingPanel.add(questionOfLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        totalQuestionLabel.setText("20");
        totalQuestionLabel.setBounds(240, 0, 18, 18);
        headingPanel.add(totalQuestionLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        questionTextArea.setColumns(20);
        questionTextArea.setRows(5);
        questionPanel.setViewportView(questionTextArea);

        answerALabel.setText("(A)");

        answerBLabel.setText("(B)");

        answerCLabel.setText("(C)");

        answerDLabel.setText("(D)");

        previousButton.setText("Previous");

        nextButton.setText("Next");

        finishedButton.setText("Finished");

        javax.swing.GroupLayout buttomButtonPanelLayout = new javax.swing.GroupLayout(buttomButtonPanel);
        buttomButtonPanel.setLayout(buttomButtonPanelLayout);
        buttomButtonPanelLayout.setHorizontalGroup(
            buttomButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(buttomButtonPanelLayout.createSequentialGroup()
                .addComponent(previousButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(nextButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 196, Short.MAX_VALUE)
                .addComponent(finishedButton)
                .addContainerGap())
        );
        buttomButtonPanelLayout.setVerticalGroup(
            buttomButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buttomButtonPanelLayout.createSequentialGroup()
                .addContainerGap(17, Short.MAX_VALUE)
                .addGroup(buttomButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(previousButton)
                    .addComponent(nextButton)
                    .addComponent(finishedButton))
                .addContainerGap())
        );

        javax.swing.GroupLayout answerPanelLayout = new javax.swing.GroupLayout(answerPanel);
        answerPanel.setLayout(answerPanelLayout);
        answerPanelLayout.setHorizontalGroup(
            answerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(answerPanelLayout.createSequentialGroup()
                .addGroup(answerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(answerPanelLayout.createSequentialGroup()
                        .addGroup(answerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(answerALabel)
                            .addComponent(answerBLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(answerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(answerBButton)
                            .addComponent(answerAButton)))
                    .addGroup(answerPanelLayout.createSequentialGroup()
                        .addComponent(answerCLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(answerCButton))
                    .addGroup(answerPanelLayout.createSequentialGroup()
                        .addComponent(answerDLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(answerDButton)))
                .addContainerGap(291, Short.MAX_VALUE))
            .addComponent(buttomButtonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        answerPanelLayout.setVerticalGroup(
            answerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(answerPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(answerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(answerALabel)
                    .addComponent(answerAButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(answerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(answerBLabel)
                    .addComponent(answerBButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(answerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(answerCLabel)
                    .addComponent(answerCButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(answerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(answerDLabel)
                    .addComponent(answerDButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttomButtonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(41, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(headingPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .addComponent(questionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .addComponent(answerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(headingPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(questionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(answerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(24, Short.MAX_VALUE))
        );

	pack();
    }

   public void populatePresentation(int question_number)
   {
object_hastable = new Hashtable();

//String qno = () question_number;	
Hashtable test_data=dbobject_question_metadata.getQuestion("1",Integer.toString(question_number));
//System.out.println(test_data.get("question_string"));
String question_label = (String)test_data.get("question_string");
String current_question_number = (String)test_data.get("question_number");
String option_1 = (String)test_data.get(1);
String option_2 = (String)test_data.get(3);
String option_3 = (String)test_data.get(4);
String option_4 = (String)test_data.get(5);
//System.out.println(option_1);
//System.out.println(option_2);
//System.out.println(option_3);
	questionNumberLabel.setText(current_question_number);
	questionTextArea.setText(question_label);
	answerAButton.setSelected(false);
	answerAButton.setText(option_1);	
	answerBButton.setText(option_2);
	answerBButton.setSelected(false);
	answerCButton.setText(option_3);
	answerCButton.setSelected(false);
	answerDButton.setText(option_4);
	answerDButton.setSelected(false);
   }

   	void addTestBeginListener(ActionListener mal) {
        beginTestButton.addActionListener(mal);
    	}

	void addTestFinishListener(ActionListener mal) {
        finishedButton.addActionListener(mal);
    	}

	void addNextQListener(ActionListener mal) {
        nextButton.addActionListener(mal);
    	}

	void addPreviousQListener(ActionListener mal) {
        previousButton.addActionListener(mal);
    	}

	void addQSelectListener(ActionListener mal) {
        answerAButton.addActionListener(mal);
	answerBButton.addActionListener(mal);
	answerCButton.addActionListener(mal);
	answerDButton.addActionListener(mal);
    	}


}

